package com.chris.design.pattern.samples.observer.jdk;

import java.util.Observable;
import java.util.Observer;

/**
 * 观察者对象
 * @author Chris
 */
public class Watcher implements Observer {
    private String newData;

    public String getNewData() {
        return newData;
    }

    public Watcher() {
        super();
    }

    public Watcher(Observable observable) {
//        this();
        observable.addObserver(this);
    }

    @Override
    public void update(Observable o, Object arg) {
//        System.out.println("被观察者对象状态新值:" + ((Watched) o).getData());
        System.out.println("观察者对象状态旧值:" + newData);
        this.newData = ((Watched) o).getData();
        System.out.println("观察者对象状态新值:" + newData);
    }
}
